/*
 *
 * Copyright (c) 2023 - future
 * @author fzh
 * @email e_341877120_mail@163.com
 * @link https://mvnrepository.com/search?q=io.github.xrfzh.cn
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package cn.xrfzh.common.axios;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Map;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class AxiosResult implements Serializable {

	private Integer code;

	private String msg;

	private Object data;

	private Map<String, Object> axiosMap;

	private static final Integer SUCCESS_CODE = AxiosEnum.SUCCESS.getCode();

	private static final Integer ERROR_CODE = AxiosEnum.ERROR.getCode();

	public static AxiosResult success(String msg) {
		return new AxiosResult(SUCCESS_CODE, msg, null, null);
	}

	public static AxiosResult success(String msg, Object data) {
		return new AxiosResult(SUCCESS_CODE, msg, data, null);
	}

	public static AxiosResult success(String msg, Map<String, Object> axiosMap) {
		return new AxiosResult(SUCCESS_CODE, msg, null, axiosMap);
	}

	public static AxiosResult success(String msg, Object data, Map<String, Object> axiosMap) {
		return new AxiosResult(SUCCESS_CODE, msg, data, axiosMap);
	}

	public static AxiosResult error(String msg) {
		return new AxiosResult(ERROR_CODE, msg, null, null);
	}

	private static AxiosResult buildAxiosResult(AxiosEnum axiosEnum) {
		return new AxiosResult(axiosEnum.getCode(), axiosEnum.getMsg(), null, null);
	}

	private static AxiosResult buildAxiosResult(AxiosEnum axiosEnum, Object data) {
		return new AxiosResult(axiosEnum.getCode(), axiosEnum.getMsg(), data, null);
	}

	private static AxiosResult buildAxiosResult(AxiosEnum axiosEnum, Map<String, Object> axiosMap) {
		return new AxiosResult(axiosEnum.getCode(), axiosEnum.getMsg(), null, axiosMap);
	}

	private static AxiosResult buildAxiosResult(AxiosEnum axiosEnum, Object data, Map<String, Object> axiosMap) {
		return new AxiosResult(axiosEnum.getCode(), axiosEnum.getMsg(), data, axiosMap);
	}

	public static AxiosResult success(AxiosEnum axiosEnum) {
		return AxiosResult.buildAxiosResult(axiosEnum);
	}

	public static AxiosResult success(AxiosEnum axiosEnum, Object data) {
		return AxiosResult.buildAxiosResult(axiosEnum, data);
	}

	public static AxiosResult success(AxiosEnum axiosEnum, Map<String, Object> axiosMap) {
		return AxiosResult.buildAxiosResult(axiosEnum, axiosMap);
	}

	public static AxiosResult success(AxiosEnum axiosEnum, Object data, Map<String, Object> axiosMap) {
		return AxiosResult.buildAxiosResult(axiosEnum, data, axiosMap);
	}

	public static AxiosResult error(AxiosEnum axiosEnum) {
		return AxiosResult.buildAxiosResult(axiosEnum);
	}

	public static AxiosResult success() {
		return new AxiosResult(AxiosEnum.SUCCESS.getCode(), AxiosEnum.SUCCESS.getMsg(), null, null);
	}

	public static AxiosResult success(Object data) {
		return new AxiosResult(AxiosEnum.SUCCESS.getCode(), AxiosEnum.SUCCESS.getMsg(), data, null);
	}

	public static AxiosResult success(Map<String, Object> axiosMap) {
		return new AxiosResult(AxiosEnum.SUCCESS.getCode(), AxiosEnum.SUCCESS.getMsg(), null, axiosMap);
	}

	public static AxiosResult success(Object data, Map<String, Object> axiosMap) {
		return new AxiosResult(AxiosEnum.SUCCESS.getCode(), AxiosEnum.SUCCESS.getMsg(), data, axiosMap);
	}

	public static AxiosResult insertSuccess() {
		return new AxiosResult(AxiosEnum.INSERT_SUCCESS.getCode(), AxiosEnum.INSERT_SUCCESS.getMsg(), null, null);
	}

	public static AxiosResult deleteSuccess() {
		return new AxiosResult(AxiosEnum.DELETE_SUCCESS.getCode(), AxiosEnum.DELETE_SUCCESS.getMsg(), null, null);
	}

	public static AxiosResult updateSuccess() {
		return new AxiosResult(AxiosEnum.UPDATE_SUCCESS.getCode(), AxiosEnum.UPDATE_SUCCESS.getMsg(), null, null);
	}

	public static AxiosResult selectSuccess(Object data) {
		return new AxiosResult(AxiosEnum.SELECT_SUCCESS.getCode(), AxiosEnum.SELECT_SUCCESS.getMsg(), data, null);
	}

	public static AxiosResult selectSuccess(Map<String, Object> axiosMap) {
		return new AxiosResult(AxiosEnum.SELECT_SUCCESS.getCode(), AxiosEnum.SELECT_SUCCESS.getMsg(), null, axiosMap);
	}

	public static AxiosResult selectSuccess(Object data, Map<String, Object> axiosMap) {
		return new AxiosResult(AxiosEnum.SELECT_SUCCESS.getCode(), AxiosEnum.SELECT_SUCCESS.getMsg(), data, axiosMap);
	}

	public static AxiosResult error() {
		return new AxiosResult(AxiosEnum.ERROR.getCode(), AxiosEnum.ERROR.getMsg(), null, null);
	}

	public static AxiosResult insertError() {
		return new AxiosResult(AxiosEnum.INSERT_ERROR.getCode(), AxiosEnum.INSERT_ERROR.getMsg(), null, null);
	}

	public static AxiosResult deleteError() {
		return new AxiosResult(AxiosEnum.DELETE_ERROR.getCode(), AxiosEnum.DELETE_ERROR.getMsg(), null, null);
	}

	public static AxiosResult updateError() {
		return new AxiosResult(AxiosEnum.UPDATE_ERROR.getCode(), AxiosEnum.UPDATE_ERROR.getMsg(), null, null);
	}

	public static AxiosResult selectError() {
		return new AxiosResult(AxiosEnum.SELECT_ERROR.getCode(), AxiosEnum.SELECT_ERROR.getMsg(), null, null);
	}

}
